﻿import QtQuick 2.0
import QtQuick.Window 2.12
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12

import "../components"

Item {
    anchors.fill: parent


    onVisibleChanged: {
        eq.model = CSetUp.getEq();
        exename.model = CSetUp.getExename(eq.getText());
    }
    Connections{  // qmlre
        target: CSetUp
        onSyhfn:{
            progressCircle.percentage=data
        }
    }

    Column{
        spacing: 20
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top:  parent.top
        anchors.topMargin:  50*dp


        CustomComboBox{
            title: "设备名称"
            editWidth: 260*dp
            id: eq
            onCurrentText: {
                exename.model = CSetUp.getExename(eq.getText());
            }
        }

        CustomComboBox{
            title: "实验名称"
            editWidth: 260*dp
            id: exename
        }

        Item { height: 20*dp; width: 20*dp }            // 占位

        Row{

            spacing: 10*dp
            height: 40*dp

            PushButton{
                id: huifu
                title: "开始恢复"
                defaultMode1: true
                onReleased: {
                    if(eq.getText()==="" || exename.getText()===""){
                        mainwindow.showToast("当前没有选中的实验", 1)
                        return
                    }

                    let res = CSetUp.hfTableData(eq.getText(), exename.getText())
                    if(res===0){
                        mainwindow.showToast("当前设备未连接", 1);
                        return
                    }else if(res===2){
                        mainwindow.showToast("运行中的设备无法进行实验恢复", 1);
                        return
                    }else if(res===4){
                        mainwindow.showToast("设备故障", 1);
                        return
                    }

                    huifu.isDisabled = true
                    quxiao.isDisabled = false
                    progressCircle.start()      // 开启进度条特效
                    progressCircle.percentage = 0
                }
            }

            PushButton {
                id:quxiao
                title: "取消恢复"
                isDisabled: true
                defaultMode2: true
                onReleased: {
                    huifu.isDisabled = false
                    quxiao.isDisabled = true
                    CSetUp.tzhf()
                    progressCircle.stop()       // 关闭进度条特效
                }
            }
        }

        Item { height: 20*dp; width: 20*dp }            // 占位

        ProgressCircle{     // 水纹波进度条
            id: progressCircle
            percentage: 1     // 进度条百分比
        }

    }
}
